package com.monitor.service.impl;

import java.io.File;

import org.apache.struts2.ServletActionContext;

import com.monitor.dao.AlbumDao;
import com.monitor.po.Album;
import com.monitor.service.AlbumService;
import com.monitor.util.FileUtil;
import com.monitor.util.Pager;

public class AlbumServiceImpl implements AlbumService {
	private AlbumDao albumDao;

	@Override
	public Pager<Album> getAlbumByUid(long uid, int pageSize, int currentPage) throws Exception {
		return albumDao.getAlbumByUid(uid, pageSize, currentPage);
	}

	public AlbumDao getAlbumDao() {
		return albumDao;
	}

	public void setAlbumDao(AlbumDao albumDao) {
		this.albumDao = albumDao;
	}

	@Override
	public boolean deleteAlbum(long uid, long albumId) throws Exception {
		Album album = albumDao.getAlbumById(albumId);
		// 判断是否是属于该用户
		if (album != null && uid == album.getOwnerUid()) {
			albumDao.deleteAlbum(album);
			String firPath = ServletActionContext.getServletContext().getRealPath("") + "/" + album.getPath();
			// 删除用户文件目录
			FileUtil.deleteFile(new File(firPath));
			return true;
		} else {
			return false;
		}
	}
}
